﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PortalCurriculo.Util.CustomControls
{
    public class Wizard : System.Web.UI.WebControls.Wizard
    {
        protected override void OnActiveStepChanged(object source, EventArgs e)
        {
            base.OnActiveStepChanged(source, e);

            List<Control> textBoxes = (from Control step in WizardSteps[ActiveStepIndex].Controls
                                       where step.GetType().Equals(typeof (TextBox))
                                       select step).ToList();

            if (textBoxes.Count == 0) return;

            TextBox firstTextBox = (from TextBox step in textBoxes
                                    orderby step.TabIndex
                                    select step).FirstOrDefault();

            if (firstTextBox != null)
                firstTextBox.Focus();
        }
    }
}